package com.sso.filter;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import com.sso.utils.CookieUtils;

public class SSOFilter implements Filter {
	private static final Logger logger = Logger.getLogger("SSOFilter");
	private static String OVERURL = null;

	@Override
	public void init(FilterConfig config) throws ServletException {
		OVERURL = config.getInitParameter("over.url");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		String token = CookieUtils.getCookieValue(req, "SSO-TOKEN");
		req.setAttribute("SSOToken", token);
		System.err.println(OVERURL);
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
		OVERURL = null;
	}

}
